/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 17:43:23
 * @LastEditTime: 2021-08-30 17:45:18
 * @LastEditors: changqing
 * @Usage: 
 */

var { timer, interval,range,from,Subject } = require('rxjs'); 
var {debounceTime,map} = require('rxjs/operators');

// debounceTime可以指定一个时间间隔，当来源Observable有新事件发生时，会等待这段时间，如果这段时间内没有新的事件发生，将这个数据发生在新的Observable上；如果在这段等待时间有新事件发生，则原来的事件不会发生在新的数据流上，并持续等待

const source = new Subject();

source.pipe(
  debounceTime(500)
).subscribe(data => {
  console.log(` ${data}`);
});

setTimeout(() => source.next(1), 0);
setTimeout(() => source.next(2), 100);
setTimeout(() => source.next(3), 200);
setTimeout(() => source.next(4), 800);
setTimeout(() => source.next(5), 1200);
setTimeout(() => source.next(6), 1800);
setTimeout(() => source.complete(), 2000);
// 3 5 6